<template>
  <div class="person">
    <h2>{{ sum }}</h2>
    <button @click="addOne">+1</button>
  </div>
</template>

<script setup name="Person" lang="ts">
//Vue3 创建以后的步骤都要在这里引入，前面多加一个on，同时函数里面还要包含一个回调函数
import {
  ref,
  onBeforeMount,
  onMounted,
  onBeforeUpdate,
  onUpdated,
  onBeforeUnmount,
  onUnmounted,
} from "vue";

let sum = ref(0);

function addOne() {
  sum.value += 1;
}

//创建 就是setup()函数，直接写就行了，没有 beforeCreated 和 created 了
console.log("创建");

//挂载
onBeforeMount(() => {
  console.log("挂载前");
});

//挂载完毕
onMounted(() => {
  console.log("挂载完毕Person");
});

//更新前
onBeforeUpdate(() => {
  console.log("更新前");
});

//更新完毕
onUpdated(() => {
  console.log("更新后");
});

//卸载前
onBeforeUnmount(() => {
  console.log("卸载前");
});

//卸载完毕
onUnmounted(() => {
  console.log("卸载完毕");
});
</script>

<style scoped>
.person {
  background-color: #c2e0f6;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 0 5px;
}
</style>